//
//  PlayLoadingView.m
//  GC_OC
//
//  Created by wlf on 2022/5/17.
//

#import "PlayLoadingView.h"

@implementation PlayLoadingView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 25;
        
    }
    return self;
}
- (UIImageView *)loadImageView {
    if (!_loadImageView) {
        _loadImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LoginLoading"]];
    }
    return _loadImageView;
}
- (void)startAnimation:(UIButton *)button
             imageName:(NSString *)imageName{
    [self endAnimation];
    [self addSubview:self.loadImageView];
    self.loadImageView.image = [UIImage imageNamed:imageName];
    self.loadImageView.x = 0;
    self.loadImageView.y = 0;
    self.loadImageView.size = button.size;
    self.rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    self.rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    self.rotationAnimation.duration = 1.5;
    self.rotationAnimation.cumulative = YES;
    self.rotationAnimation.repeatCount = MAXFLOAT;
    [self.loadImageView.layer addAnimation:self.rotationAnimation forKey:@"rotationAnimation"];
}
- (void)endAnimation {
    [self.loadImageView.layer removeAllAnimations];
    [self.loadImageView removeFromSuperview];
}
@end
